import param
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
import panel as pn
import numpy as np
pn.extension()
import plotly.express as px
# make plots static
%matplotlib inline
x_data = 6*np.random.random(50)
y_data = np.sin(x_data)
# create a simple dataframe of animal ratings
# df = pd.DataFrame({'Animal':['Pig', 'Goat' ,'Sheep', 'Frog', 'Goat', 'Goat', 'Pig', 'Sheep',
# 'Octopus', 'Goat', 'Pig', 'Sheep', 'Octopus', 'Frog', 'Goat', 'Goat',
# 'Pig', 'Pig', 'Sheep', 'Frog', 'Frog', 'Octopus', 'Octopus'],
# 'Rating':[3, 10, 3, 2, 9, 10, 4, 1,
# 1, 8, 5, 6, 2, 4, 10, 9,
# 5, 5, 3, 2, 3, 1, 1]})
# df.to_csv('animals.csv')
# df = pd.read_csv('animals.csv')
url = 'https://raw.githubusercontent.com/aimalz/plasticc-explorer/master/animals.csv'
df = pd.read_csv(url)
df_pd = pd.DataFrame()
df_pd['x_vals'] = np.arange(10)
df_pd['y_vals'] = np.random.random(10)
# create a class containing an animal selector drop-down, various plots, and a data table output
class RatingsDashboard(param.Parameterized):
# drop down selector widget containing the list of animals, with the default being 'Goat'
Animal = param.ObjectSelector(default='Goat', objects=list(df.Animal.unique()))
# create data set containing only the data applicable to the animal in the drop down selector
def get_data(self):
class_df = df[(df.Animal==self.Animal)].copy()
return class_df
# seaborn box plot for the chosen animal
def box_view(self):
data = self.get_data()
ax = sns.boxplot(data['Rating'])
plt.close()
return ax.figure
# table of data for the chosen animal
def table_view(self):
data = self.get_data()
return data
# table of data for the chosen animal
<<<<<<< Updated upstream
def plot_view(self):
data = self.get_data()
fig = px.scatter(x=x_data, y=y_data)
#fig.show()
return fig.show()
=======
"""def plot_view(self):
data = self.get_data()
fig = px.scatter(x=x_data, y=y_data)
#fig.show()
return fig.show()"""
def select_row(self):
row=0
data = self.get_data()
animal = data.iloc[0]['Animal']
animal_to_number = {'Pig': 1, 'Goat':2 ,'Sheep':3,
'Frog':4, 'Octopus':5}
row = animal_to_number[animal]
fig, ax = plt.subplots()
ax.plot(df_pd['x_vals'], row*.8*df_pd['y_vals'], 'o')
ax.set_xlabel('xxs')
ax.set_ylim(0, row+1)
plt.close()
return ax.figure
>>>>>>> Stashed changes
# create an instance of the class
rd = RatingsDashboard(name='')
# create a title for the dashboard
dashboard_title = '# Animal Ratings Dashboard'
# create some text describing the dashboard
dashboard_desc = 'An example of a simple interactive HoloViz Panel dashboard using a'\
' dummy data set of animal ratings.'
# create a dashboard, defining the layout as one column containing the
# dashboard title, dashboard description, 'Animal' drop down selector,
# box plot, and data table
dashboard = pn.Column(dashboard_title,
dashboard_desc,
rd.param, # 'Animal' drop down selector
rd.select_row, # data plot
rd.box_view, # box plot
rd.table_view, # data table
<<<<<<< Updated upstream
rd.plot_view # data plot
=======
#rd.plot_view, # data plot
>>>>>>> Stashed changes
)